<template>
  <div class="container">
    <div>
      <el-row :gutter="12">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item>
              <!-- <el-radio v-model="form.radioData" label="日">按日期：</el-radio> -->
              <span>查询日期：</span>
              <el-date-picker v-model="form.valueDay" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <!-- <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="查询区域：">
              <el-select v-model="form.typeValue" placeholder="请选择">
                <el-option
                  v-for="item in selectCarType"
                  :key="item.index"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col> -->
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="查询区域：">
              <el-select
                v-model="CLIENT_GROUP_NAME"
                placeholder="请选择分组"
              >
                <el-option
                  v-for="(item, index) in groupingList"
                  :value="item.CLIENT_GROUP_NO"
                  :label="item.CLIENT_GROUP_NAME"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float:left">
            <el-button size="mini" type="primary" @click="getlistdata">查 询</el-button>
            <el-button size="mini" type="success" @click="exportExcel">导 出</el-button>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)"
      highlight-current-row
    >
      <el-table-column prop="RGrade" label="道路等级" align="center"></el-table-column>
      <el-table-column prop="ROADNUM" label="考核道路数" align="center"></el-table-column>
      <el-table-column prop="WORKROADNUM" label="作业道路数" align="center"></el-table-column>
      <el-table-column prop="NOWORKROADNUM" label="未作业道路数"></el-table-column>
      <el-table-column prop="WORKROADNUMRTS" label="达标道路数"></el-table-column>
      <el-table-column prop="NOWORKROADNUMRTS" label="未达标道路数"></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      form: {
        typeList: [{ label: '洗扫车', value: '洗扫' }, { label: '洒水车', value: '洒水' }, { label: '冲洗车', value: '冲洗' }, { label: '机扫车', value: '机扫' }],
        typeValue: localStorage.getItem('CLIENT_NO'),
        radioData: '日',
        valueDay: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        valueMonth: ''
      },
      // selectCarType: [{
      //   value: '00000',
      //   label: '全部'
      // }, {
      //   value: '0000001',
      //   label: '河西区'
      // }, {
      //   value: '0000005',
      //   label: '和平区'
      // }, {
      //   value: '0000004',
      //   label: '南开区'
      // }, {
      //   value: '0000006',
      //   label: '河东区'
      // }, {
      //   value: '0000007',
      //   label: '河北区'
      // }, {
      //   value: '0000009',
      //   label: '东丽区'
      // }, {
      //   value: '0000011',
      //   label: '西青区'
      // }, {
      //   value: '0000008',
      //   label: '红桥区'
      // }, {
      //   value: '0000015',
      //   label: '武清区'
      // }, {
      //   value: '0000016',
      //   label: '静海区'
      // }, {
      //   value: '0000017',
      //   label: '宁河区'
      // }, {
      //   value: '0000010',
      //   label: '津南区'
      // }, {
      //   value: '0000012',
      //   label: '北辰区'
      // }, {
      //   value: '0000019',
      //   label: '滨海新区'
      // }, {
      //   value: '0000014',
      //   label: '蓟州区'
      // }, {
      //   value: '0000018',
      //   label: '宝坻区'
      // }],
      tableData: [],
      groupingList: [],
      CLIENT_GROUP_NAME: ''
    }
  },
  created () {
    this.getGroupingList();
  },
  methods: {
    // 获得分组列表
    async getGroupingList () {
      var url =
        "Vehicle/GetClientInfo?client_no=" + localStorage.getItem("CLIENT_NO"); // zxdata
      let { data } = await this.$Http.get(url);
      this.groupingList = data;
      this.groupingList.unshift({ "CLIENT_GROUP_NO": localStorage.getItem("CLIENT_NO"), "CLIENT_GROUP_NAME": "全部" })
      this.CLIENT_GROUP_NAME = data[0].CLIENT_GROUP_NO;
      // this.getRoadList(data[0].CLIENT_GROUP_NO);
      this.getlistdata();
    },
    async getlistdata () {
      },
    async getlistdata1 () {
      this.tableData = []
      this.currentPage = 1;
      var date = ''
      if (this.form.radioData === '日') {
        date = this.form.valueDay
      }
      if (this.form.radioData === '月') {
        date = this.form.valueMonth
      }
      var url = 'Vehicle/GetExcelCar4?area=' + this.CLIENT_GROUP_NAME + '&type=&date=' + date // + '&ClientNo=' + localStorage.getItem('CLIENT_NO')
      console.log('url=' + url)
      const { data } = await this.$Http.get(url)
      this.tableData = data
    },
    // 导出Excel
    exportExcel () {
      let excelName = '道路考核统计表'
      const tHeader = ['道路等级', '考核道路数', '作业道路数', '未作业道路数', '达标道路数', '未达标道路数']
      const filterVal = ['RGrade', 'ROADNUM', 'WORKNOROADNUM', 'NOWORKROADNUM', 'WORKNOROADNUMRTS', 'NOWORKROADNUMRTS']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
    height: 40px;
}
</style>